#!/usr/bin/python
# Copyright 2011 Alex K (wtwf.com) All rights reserved.

"""ftplog: gets cvs file from sma sunnyboy webbox data logger via ftp.
"""
import datetime
import ftplib
import os
import sys

def Main(args):
  today = datetime.date.today().isoformat()
  # today = '2011-06-14'
  ftp = ftplib.FTP('10.1.10.27')
  ftp.login('user', os.environ['WEBBOX_PASSWORD'])
  ftp.cwd('DATA/%s' % today[0:4])  # e.g. DATA/2011
  ftp.retrbinary('RETR %s.csv' % today, open('%s.csv' % today, 'wb').write)
  ftp.quit()
  print 'wrote: %s.csv' % today


if __name__ == '__main__':
  Main(sys.argv)


